/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cinema.client.cinemaclient.tablemodels;

import com.cinema.client.cinemaclient.model.Movie;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Zsolt Szecsi
 */
public class MovieTableModel extends AbstractTableModel {

    private static final String[] COLUMNS = {"Id", "Title", "Director", "Year"};
    private List<Movie> movies;

    public MovieTableModel(List<Movie> movies) {
        this.movies = movies;
    }

    @Override
    public int getRowCount() {
        return movies.size();
    }

    @Override
    public int getColumnCount() {
        return COLUMNS.length;
    }

    @Override
    public Object getValueAt(int i, int i1) {
        switch (i1) {
            case 0:
                return movies.get(i).getId();
            case 1:
                return movies.get(i).getTitle();
            case 2:
                return movies.get(i).getDirector();
            case 3:
                return "" + movies.get(i).getYear();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int i) {
        return COLUMNS[i];
    }

    public void setMovies(List<Movie> movies) {
        this.movies = movies;
    }

}
